package org.example.config;

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import org.example.Interface.HCNetSDK;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class BeanFactory {
    @Bean
    HCNetSDK hcNetSDK() {
        String userdir = System.getProperty("user.dir");
        String dllpath = userdir + "\\lib\\HCNetSDK.dll";
        System.out.println("Load HCNetSDK from Path: " + dllpath);
        HCNetSDK sdk = (HCNetSDK) Native.loadLibrary(dllpath, HCNetSDK.class);
        sdk.NET_DVR_Init();
        sdk.NET_DVR_SetExceptionCallBack_V30(0, 0, new FExceptionCallBack_Imp(), null);
        sdk.NET_DVR_SetLogToFile(3, userdir + "\\sdkLog", false);
        return sdk;
    }

    private static class FExceptionCallBack_Imp implements HCNetSDK.FExceptionCallBack {
        public void invoke(int dwType, int lUserID, int lHandle, Pointer pUser) {
            System.out.println("异常事件类型:"+dwType);
            return;
        }
    }
}
